package com.cloudcc.mobile.presenter;

import java.util.Calendar;
import java.util.Date;

import android.text.TextUtils;

import com.cloudcc.cloudframe.bus.EventEngine;
import com.cloudcc.cloudframe.net.ErrorInfo;
import com.cloudcc.cloudframe.net.RequestListener;
import com.cloudcc.mobile.dao.ScheduleEngine;
import com.cloudcc.mobile.dao.impl.ScheduleEngineImpl;
import com.cloudcc.mobile.event.ScheduleEventList.ScheduleListEvent;

public class SchedulePresenter extends BasePresenter {

	private ScheduleEngine mEngine;

	public SchedulePresenter() {
		super();
		mEngine = new ScheduleEngineImpl();
	}

	/**
	 * 获取日程列表
	 * 
	 * @param date
	 */
	public void getScheduleList(String belongtoid, Date date) {
		ScheduleListEvent event = new ScheduleListEvent();
		if (date == null) {
			event.setOk(false);
			event.setMessage("查询参数错误...");
			EventEngine.post(event);
			return;
		}
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		mEngine.getScheduleList(belongtoid,
				String.valueOf(cal.get(Calendar.YEAR)),
				String.valueOf(cal.get(Calendar.MONTH) + 1), event);
	}

	/**
	 * 完成
	 * 
	 * @param id
	 * @param listener
	 */
	public void completeTask(String id, RequestListener listener) {
		if (id == null || TextUtils.isEmpty(id)) {
			listener.onFailure(ErrorInfo.get(2000, "参数不能为空"));
			return;
		}

		mEngine.completeOneTask(id, listener);
	}

}
